#include"caculate.h"
int cmp_char(const void* p1, const void* p2)
{
	return *((char*)p1) - *((char*)p2);
}
int cmp_int(const void* p1, const void* p2)
{
	return *((int*)p1) - *((int*)p2);
}
int cmp_struct_age(const void* p1, const void* p2)
{
	return (((struct S*)p1)->age) - (((struct S*)p2)->age);
}
int cmp_struct_name(const void* p1, const void* p2)
{
	return *((char*)p1) - *((char*)p2);
}


void swap(char* p1, char* p2, int wide)
{
	int i = 0;
	for (i = 0; i < wide; i++)
	{
		char tmp = 0;
		tmp = *p1;
		*p1 = *p2;
		*p2 = tmp;
		p1++;
		p2++;
	}
}

void bubble_sort(void* base, int sz, int wide, int(*cmp)(const void* p1, const void* p2))
{
	int i = 0;
	int j = 0;
	for (i = 0; i < sz - 1; i++)
	{
		for (j = 0; j < sz - 1 - i; j++)
		{
			if (cmp((char*)base + wide * j, (char*)base + wide * (j + 1)) > 0)
				swap((char*)base + wide * j, (char*)base + wide * (j + 1), wide);
		}
	}
}